#@layoutMain()
#define mainMessage()

<fieldset class="layui-elem-field layui-field-title">
	<legend>
		友情链接管理
	</legend>
</fieldset>
<div style="padding-top: 20px; padding-left: 10px;">
	<div>
		<button class="layui-btn layuiadmin-btn-list" data-type="batchdel" onclick="addArcType()">添加</button>
	</div>
	<div>
		<table width="100%" id="linkListTable" ></table>
	</div>
</div>

#end

#define js()

<script>

layui.use(['element','form','table'], function(){
    var form=layui.form;
	  var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
	  $ = layui.jquery; // 使用jquery
	  table = layui.table;
	  
	  table.render({
	    elem: '#linkListTable'
	    ,url:'/admin/link/linkListTable'
	    ,cols: [[
		  {field:'lid', width:80, title: '编号', sort: true,align:'center'}
	      ,{field:'name', width:300,title: '链接名称'}
	      ,{field:'url', title: '链接地址'}
	      ,{field:'sort', width:100, title: '排列序号',align:'center'}
	      ,{field:'action', width:150, title: '操作',align:'center',templet:formatAction}
	    ]]
	    ,page: true
	  });

});

//删除一个链接
function deleteOne(lid){
	layer.confirm('您确定要删除这条记录吗？', {
    title:"系统提示"
	  ,btn: ['确定','取消'] //按钮
	}, function(){
		layer.closeAll('dialog');
		window.location.href="/admin/link/deleteLink/"+lid;
	}, function(){
	  
	});
}

//添加友情链接
function addArcType(){
	layer.open({
		  type: 2,
		  title: '添加友情链接',
		  area: ['500px', '400px'],
		  content: '/admin/addLink.html' //iframe的url
		});
}

//修改友情链接
function modifyArcType(lid){
	layer.open({
		  type: 2,
		  title: '修改友情链接',
		  area: ['500px', '400px'],
		  content: '/admin/addLink.html?id='+lid //iframe的url
		});
}

//表格右侧的操作
function formatAction(d){
	return "<button class='layui-btn layui-btn-normal layui-btn-xs' onclick='modifyArcType("+d.lid+")'><i class='layui-icon layui-icon-edit'></i>编辑</button>"
	+"<button class='layui-btn layui-btn-warm layui-btn-xs' onclick='deleteOne("+d.lid+")'><i class='layui-icon layui-icon-delete' ></i>删除</button>";
}

</script>
	
#end